/**
 * Created by karim on 2017/1/17.
 */

$('#rightMain_title').html('用户列表');	
$(".leftNav a:nth-child(5)").css("background","#1a63be")
var searchtext =null,id=null;
if(window.location.search!=""){
	id = getUrlParam("id");
	searchtext = getUrlParam("sign");
	$("#searchText").val(searchtext);
}
function addUserBtn(){
	window.location.href='editUser.html?id=6YOd';
};
$.ajax({
	url:"user/findUser.html",
	type:"post",
	data:{
		id:id,
		searchText:searchtext
    },
	success:function(result){
	 result=JSON.parse(result);
	 if(result.result!=0){
		 setTimeout(function(){
      		swal(" 查询失败！",result.message, "error");
      	},0);
		 return false;
	 };
	 $("#userNum").append(result.data.length);
	 for(var i=0;i<result.data.length;i++){
		 var myA='<a href="editUser.html?id='+result.data[i].id+'" class="tagList">'+
		 '<table cellspacing="1" cellpadding="0"><tbody cellspacing="1" cellpadding="0" style="padding:0;margin:0;width:100%">'+
		 '<tr><td>帐号</td><td>'+result.data[i].username+'</td></tr>'+
		 '<tr><td>真实姓名</td><td>'+result.data[i].truename+'</td></tr>'+
		 '<tr><td>手机</td><td>'+result.data[i].mobile+'</td></tr>'+
		 '<tr><td>登录时间</td><td>'+getLoginTime(result.data[i].login_time)+'</td></tr>'+
		 '</tbody></table></a>';
		 $("#userList").append(myA);
	 };
	 var myWhite = '<div id="myWhite" style="height:80px;width:100%;background:transparent"></div>'
		 $("#userList").append(myWhite);
 },
 error:function(err){
	 console.log(err);
 }
 })
	 /**
	  * 时间戳格式化
	  */
	var getLoginTime = function(loginTime){
		if(loginTime==0){
			return "尚未登录";
		}
		return  new Date(parseInt(loginTime) * 1000).toLocaleString().substr(0,18)
	} ;
	
	/**
	 * 搜索
	 */
	$("#searchBtn").click(function(){
		var searVal=$("#searchText").val();
		if(searVal.length==0){
	    	setTimeout(function(){
	    		swal("查询内容为空!");
	    		$("div h2").css("fong-size","20px");
	    	},0)
		}else{
			window.location.href='user.html?sign='+searVal;
		}
	});
	$("#addBtn").on('click',function(){
		var searVal=$("#searchText").val();
	});
	

